package com.cg;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

/**
 * thenAccept：入参，无返回值
 */
public class CompleteFutureTest02 {
    public static void main(String[] args) throws InterruptedException {
//        CompletableFuture
//                //让儿子去打酱油
//                .supplyAsync(()-> {
//                    try {
//                        TimeUnit.SECONDS.sleep(1);
//                        System.out.println("儿子跑步去打酱油");
//                        TimeUnit.SECONDS.sleep(2);
//                        System.out.println("酱油买回来了");
//                    } catch (InterruptedException e) {
//                        e.printStackTrace();
//                    }
//                    return "酱油";
//                })
//                //告诉我一声
//                .thenAccept(oil->{
//                    System.out.println("用买来的" + oil + "做菜");
//                });
//        System.out.println("做菜中...");
//        Thread.currentThread().join();

        CompletableFuture
                //让儿子去打酱油
                .supplyAsync(()-> {
                    try {
                        TimeUnit.SECONDS.sleep(1);
                        System.out.println("儿子跑步去打酱油");
                        TimeUnit.SECONDS.sleep(2);
                        System.out.println("酱油买回来了");
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    return "酱油";
                })
                //告诉我一声
                .thenAccept(oil->{
                    System.out.println("用买来的" + oil + "做菜");
                });
        System.out.println("做菜中...");
        Thread.currentThread().join();
    }
}
